var myPromise

function outf(text) {
  var mypre = document.getElementById("output");
  mypre.innerHTML = mypre.innerHTML + text;
}

function builtinRead(x) {
  if (Sk.builtinFiles === undefined || Sk.builtinFiles["files"][x] === undefined)
    throw "File not found: '" + x + "'";
  return Sk.builtinFiles["files"][x];
}

function runit(editor) {
  var prog = editor.getValue();
  var mypre = document.getElementById("output");

  mypre.innerHTML = '';
  Sk.pre = "output";
  Sk.configure({ output: outf, read: builtinRead, python3:true});

  (Sk.TurtleGraphics || (Sk.TurtleGraphics = {})).target = 'mycanvas';

  myPromise = Sk.misceval.asyncToPromise(function() {
    return Sk.importMainWithBody("<stdin>", false, prog, true);
  });

  myPromise.then(function(mod) {
      console.log('编译成功');
    },
    function(err) {
      console.log(err.toString());
    });
}

function stopit(editor) {

}

export default {
  runit,
  stopit
}